package cn.bb.action;

import cn.bb.pojo.Admin;
import cn.bb.service.IAdminService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class AdminAction extends ActionSupport implements ModelDriven<Object> {
    private Admin admin;
    @Autowired
    private IAdminService adminService;
    /*登录*/
    public String loginManager(){
        System.out.println(admin);

        Admin a = adminService.loginUser(admin);
        if(a != null){
            Map<String,Object> map = ActionContext.getContext().getSession();
            map.put("username",a.getUsername());
            return SUCCESS;
        }
            return "loginFalse";
    }
    public String layout(){
        Map<String,Object> map = ActionContext.getContext().getSession();
        map.put("username",null);
        return SUCCESS;
    }
    public IAdminService getAdminService() {

        return adminService;
    }

    public void setAdminService(IAdminService adminService) {
        this.adminService = adminService;
    }

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    @Override
    public Admin getModel() {
        if(admin == null){
            admin = new Admin();
        }
        return admin;
    }
}
